package com.ruoyi.web.controller.his;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.his.domain.HisPunish;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.IHisEngineAnalysisService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/system/warnAnalysis")
public class HisEngineWarnAnalysisController extends BaseController {

    @Autowired
    private IHisEngineAnalysisService hisEngineAnalysisService;
    @Autowired
    private RedisCache redisCache;
    @ApiOperation("校验逾期预警")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/VerifyWarning")
    public TableDataInfo list(HisVerifyOverdueWarning hisVerifyOverdueWarning)
    {
        startPage();
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        hisVerifyOverdueWarning.setHospitalIds(hospitalIds);
        hisVerifyOverdueWarning.setSignatures(signatures);
        List<HisVerifyOverdueWarning> hisVerifyOverdueWarnings
                = hisEngineAnalysisService.verifyOverdueWarningList(hisVerifyOverdueWarning);

        return getDataTable(hisVerifyOverdueWarnings);
    }
    @ApiOperation("校验逾期预警")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/myVerifyWarning")
    public TableDataInfo myVerifyWarning(HisVerifyOverdueWarning hisVerifyOverdueWarning)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        hisVerifyOverdueWarning.setRegisterNumber(loginUser.getRegisterNumber());
        List<HisVerifyOverdueWarning> hisVerifyOverdueWarnings
                = hisEngineAnalysisService.verifyOverdueWarningList(hisVerifyOverdueWarning);

        return getDataTable(hisVerifyOverdueWarnings);
    }

    @ApiOperation("许可证逾期预警")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/LicencedWarning")
    public TableDataInfo licencedWarning(HisLicensedOverWarning hisLicensedOverWarning)
    {
        startPage();
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        hisLicensedOverWarning.setHospitalIds(hospitalIds);
        hisLicensedOverWarning.setSignatures(signatures);
        List<HisLicensedOverWarning> hisLicensedOverWarnings
                = hisEngineAnalysisService.hisLicensedOverWarningList(hisLicensedOverWarning);
        return getDataTable(hisLicensedOverWarnings);
    }

    @GetMapping("/myLicencedWarning")
    public TableDataInfo mylicencedWarning(HisLicensedOverWarning hisLicensedOverWarning)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        hisLicensedOverWarning.setHospitalId(loginUser.getHospitalId());
        hisLicensedOverWarning.setSignature(loginUser.getSignature());
        List<HisLicensedOverWarning> hisLicensedOverWarnings
                = hisEngineAnalysisService.hisLicensedOverWarningList(hisLicensedOverWarning);

        return getDataTable(hisLicensedOverWarnings);
    }
    @GetMapping("/mychildBeyondWarn")
    public TableDataInfo mychildBeyondWarning(HisChildBeyondWarning hisChildBeyondWarning)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        hisChildBeyondWarning.setRegisterNumber(loginUser.getRegisterNumber());
        List<HisChildBeyondWarning> hisChildBeyondWarnings = hisEngineAnalysisService.hisChildBeyondWarning(hisChildBeyondWarning);
        return getDataTable(hisChildBeyondWarnings);
    }
    @ApiOperation("儿科超范围预警")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/childBeyondWarn")
    public TableDataInfo childBeyondWarning(HisChildBeyondWarning hisChildBeyondWarning)
    {
        startPage();
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        hisChildBeyondWarning.setHospitalIds(hospitalIds);
        hisChildBeyondWarning.setSignatures(signatures);
        List<HisChildBeyondWarning> hisChildBeyondWarnings = hisEngineAnalysisService.hisChildBeyondWarning(hisChildBeyondWarning);
        return getDataTable(hisChildBeyondWarnings);
    }

    @ApiOperation("儿科超范围预警")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/childBeyondWarnList")
    public TableDataInfo childBeyondWarningList(HisChildBeyondWarning hisChildBeyondWarning)
    {
        startPage();
        List<HisChildBeyondWarning> hisChildBeyondWarnings = hisEngineAnalysisService.hisChildBeyondWarningList(hisChildBeyondWarning);
        return getDataTable(hisChildBeyondWarnings);
    }

    @ApiOperation("儿科超范围预警")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/childBeyondWarnList1")
    public TableDataInfo childBeyondWarningList1(HisChildBeyondWarning hisChildBeyondWarning)
    {
        startPage();
        List<HisChildBeyondWarning> hisChildBeyondWarnings = hisEngineAnalysisService.hisChildBeyondWarningList1(hisChildBeyondWarning);
        return getDataTable(hisChildBeyondWarnings);
    }
    //处方处置统计详情
    @GetMapping("/childBeyondWarnInfo")
    public TableDataInfo childBeyondWarnInfo(HisPunish hisPunish)
    {
        startPage();
        List<HisPunish> hisPunishs = hisEngineAnalysisService.childBeyondWarnInfo(hisPunish);
        return getDataTable(hisPunishs);
    }

    @ApiOperation("儿科超范围预警详情")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/childBeyondWarn/details")
    public AjaxResult childBeyondWarningDetails(HisChildBeyondWarning hisChildBeyondWarning)
    {
        HisChildBeyondWarningDetails hisChildBeyondWarningDetails = hisEngineAnalysisService.hisChildBeyondWarningDetails(hisChildBeyondWarning);
        return AjaxResult.success(hisChildBeyondWarningDetails);
    }
    @GetMapping("/mynoRightsKj")
    public TableDataInfo mynoRightsKj(HisPunish hisPunish)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        hisPunish.setHospitalId(loginUser.getHospitalId());
        hisPunish.setSignature(loginUser.getSignature());
        List<HisPunish> hisPunishs = hisEngineAnalysisService.childBeyondWarnInfo(hisPunish);
        return getDataTable(hisPunishs);
    }
    @ApiOperation("抗菌药物预警")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/noRightsKj")
    public TableDataInfo noRightsKj(HisChildBeyondWarning hisChildBeyondWarning)
    {
        startPage();
        List<HisChildBeyondWarning> hisChildBeyondWarnings = hisEngineAnalysisService.hisNoRightsKj(hisChildBeyondWarning);
        return getDataTable(hisChildBeyondWarnings);
    }

    @ApiOperation("抗菌药物预警详情")
//    @PreAuthorize("@ss.hasPermi('system:rights:list')")
    @GetMapping("/noRightsKj/details")
    public AjaxResult noRightsKjDetails(HisChildBeyondWarning hisChildBeyondWarning)
    {
        HisHasNoKjWarningDetails hisHasNoKjWarningDetails = hisEngineAnalysisService.hisNoRightsKjDetails(hisChildBeyondWarning);
        return AjaxResult.success(hisHasNoKjWarningDetails);
    }


}
